﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;

namespace qna.Business {
	public class Subject : BusinessObject {
		public int Id { get; set; }
		public string Name { get; set; }
		public string Code { get; set; }

		protected override string TableName {
			get { return "subject"; }
		}

		protected override BusinessObject New() {
			return new Subject();
		}

		public override IDictionary<string, object> Attributes {
			get {
				IDictionary<string, object> attrs = new Dictionary<string, object>();
				attrs["Id"] = Id;
				attrs["Name"] = Name;
				attrs["Code"] = Code;
				return attrs;
			}
		}

		public override void ReadAttributes(System.Data.SqlClient.SqlDataReader dr) {
			Id = (int)dr["Id"];
			Name = dr["Name"].ToString();
			Code = dr["Code"].ToString();
		}

		public IList<Subject> GetByUser(int id) {
			//todo implement real logic
			IList<Subject> subjects = new List<Subject>();
			subjects = ((List<BusinessObject>)GetAll()).ConvertAll<Subject>(delegate(BusinessObject bo) {
				return (Subject)bo;
			});
			return subjects;
		}

        [DataObjectMethod(DataObjectMethodType.Select)]
        public IList<Subject> ListSubject(int id)
        {
           return GetByUser(Id).Cast<Subject>().ToList<Subject>();    
        }
	}
}